package com.sesum;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Decline extends Sesum {
	
	private static final int DECLINE_FAILED = 1;
	private static final int DECLINE_OK = 2;
	

	@Override
	protected Dialog onCreateDialog(int id) {

		switch (id) {

		case DECLINE_FAILED:
			return new AlertDialog.Builder(this)

			.setTitle("Resultado")

			.setMessage("La baja ha fallado, inténtelo de nuevo mas tarde")

			.setNeutralButton("Aceptar",

			new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog,

				int which) {

				}

			}).create();
			
		case DECLINE_OK:
			return new AlertDialog.Builder(this)

			.setTitle("Resultado")

			.setMessage("Baja efectuada correctamente")

			.setNeutralButton("Aceptar",

			new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog,

				int which) {

				}

			}).create();

		default:
			break;
		}
		return null;
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.decline);
		// Get the EditText and Button References
		final EditText etUsername = (EditText) findViewById(R.id.username);
		final EditText etPassword = (EditText) findViewById(R.id.password);
		Button btnDecline = (Button) findViewById(R.id.decline_button);
		Button btnCancel = (Button) findViewById(R.id.cancel_button);
		// lblResult = (TextView)findViewById(R.id.result);

		btnDecline.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Check Login
					boolean result = decline(etUsername.getText().toString(), etPassword.getText().toString());
					if (result) {
						showDialog(DECLINE_OK);
						Intent intent = new Intent(getApplicationContext(),
								Login.class);
						startActivity(intent);
					} else {
						showDialog(DECLINE_FAILED);
					}
				}
		});

		btnCancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();

			}
		});

	}

}
